<template>
	<el-dialog v-model="dialogShow" title="编辑" width="700" :before-close="cancel">
		<EForm
			v-if="dialogShow"
			ref="dialogForm"
			:form-options="editFormOptions"
			:form-label-width="'100px'"
			:form-rules="editFormRules"
			:form-data-current="formData"
		>
			<template #valueRange="{ scope: { formData } }">
				<div class="flex gap-2 w-full">
					<el-input v-model.number="formData.lowerLimit" /> -
					<el-input v-model.number="formData.upperLimit" />
				</div>
			</template>
		</EForm>
		<template #footer>
			<div class="dialog-footer">
				<el-button type="primary" @click="save">保 存</el-button>
				<el-button @click="cancel">取 消</el-button>
			</div>
		</template>
	</el-dialog>
</template>
<script setup>
import { editFormOptions, editFormRules } from './control';
import EForm from '/@/components/e-form';
import { ElMessage } from 'element-plus';

// const router = useRouter();
const emits = defineEmits(['success']);

const dialogForm = ref();
const dialogShow = ref(false);
const dialogType = ref();
const formData = ref();

const show = (data) => {
	formData.value = data;
	dialogShow.value = true;
	dialogType.value = 0;
};
const closeDialog = () => {
	dialogShow.value = false;
	dialogType.value = undefined;
	dialogForm.value.handleRefresh();
};

const cancel = () => {
	closeDialog();
};

const save = async () => {
	dialogForm.value.handleValidate(async (validate) => {
		if (validate) {
			const data = { ...dialogForm.value.formData };
			// await submit(types.warningLevel, 'put', data);
			ElMessage.success('操作成功');
			emits('success', data);
			cancel();
		}
	});
};

defineExpose({
	show,
});
</script>
